<?php
require_once "php/config.php";

$file = $svnURL.$filePath;

$props = getSvnFileProperties($file);
$fileInfo = getSvnFileInfo($file);
$upDir = getUpDir($fileInfo['url']);
$repositoryRoot = $fileInfo['repository-root'];
$basePath = str_replace($svnURL,'',$repositoryRoot);
$baseFilePath = str_replace("//","/",str_replace($basePath,'',dirname($filePath)));

$revs = getPreviousRevisions($file);

header("Content-Type: application/xml");
echo "<?xml version=\"1.0\"?>\n";
echo "<?xml-stylesheet type=\"text/xsl\" href=\"{$path}/svnindex.xsl.php\"?>\n";
?>
<!DOCTYPE svn [
  <!ELEMENT svn   (index)>
  <!ATTLIST svn   version CDATA #REQUIRED
                  href    CDATA #REQUIRED>
  <!ELEMENT index (updir?, (file | dir)*)>
  <!ATTLIST index name    CDATA #IMPLIED
                  path    CDATA #IMPLIED
                  rev     CDATA #IMPLIED
                  base    CDATA #IMPLIED>
  <!ELEMENT updir EMPTY>
  <!ELEMENT information EMPTY>
  <!ATTLIST information  name    CDATA #REQUIRED
                         href    CDATA #REQUIRED>
  <!ELEMENT file  EMPTY>
  <!ATTLIST file  name    CDATA #REQUIRED
                  href    CDATA #REQUIRED>
  <!ELEMENT dir   EMPTY>

  <!ATTLIST dir   name    CDATA #REQUIRED
                  href    CDATA #REQUIRED>
]>
<svn version="<?php echo $svnVersion; ?>"
     href="http://subversion.tigris.org/" pretty="true" nsvn="<?php echo NICE_SVN_VERSION; ?>">
  <index rev="<?php echo $fileInfo['revision'] ?>" path="<?echo $baseFilePath ?>/<? echo $fileInfo['name'] ?>" base="<?php echo $basePath ?>">
    <updir href="<?php echo  $upDir  ?>"/>
    <information
       <?php  foreach ($fileInfo as $key => $value) : ?>
           <?php if(!$value) continue; ?>
           <?php echo $key ?>="<?php echo $value ?>"
       <?php endforeach; ?>
    />
    <revisions>
      <?php  foreach ($revs as $revision) : ?>
           <revision number="<?php echo $revision['rev'] ?>" by="<?php echo $revision['by'] ?>" on="<?php echo $revision['on'] ?>" prev="<?php echo $revision['prev'] ?>" />
       <?php endforeach; ?>
    </revisions>
    <code src="<?php echo $fileInfo['url'] ?>" ></code>
    <properties>
       <?php  foreach ($props as $prop => $values) : ?>
           <property name="<?php echo $prop ?>">
            <?php foreach( $values as $value ) : ?>
               <value value="<?php echo $value ?>" />
            <?php endforeach; ?>
           </property>
       <?php endforeach; ?>
    </properties>
  </index>
</svn>


